package com.joysuch.wwyt.bp.controller;


import com.joysuch.wwyt.bp.bean.inspect.BPInspectItemBean;
import com.joysuch.wwyt.bp.bean.inspect.BPInspectItemQueryBean;
import com.joysuch.wwyt.bp.entity.inspect.BPInspectItem;
import com.joysuch.wwyt.bp.service.BPInspectItemService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.common.util.PageDataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/bp/inspect-item")
@Api(tags = "巡检点-检查项目管理")
@CrossOrigin
public class BPInspectItemController {

    @Autowired
    private BPInspectItemService inspectItemService;

    @RequestMapping("/list")
    @ApiOperation(value = "01 巡检项项目列表", response = BPInspectItemBean.class)
    public ResultBean list(BPInspectItemQueryBean queryBean, Pageable pageable) {
        pageable = PageDataUtils.addOrderByDesc(pageable, "createTime");
        Page<BPInspectItemBean> page = inspectItemService.findList(queryBean, pageable);
        return ResultBean.pageData(page);

    }

    @PostMapping("/save")
    @RequiresPermissions("bp:inspect-item:save")
    @ApiOperation(value = "02 保存巡检项项目", response = BPInspectItem.class)
    public ResultBean save(@RequestBody BPInspectItemBean bean) {
        BPInspectItem inspectItem = inspectItemService.save(bean);
        return ResultBean.success(inspectItem);
    }

    @PostMapping("/saveList")
    @ApiOperation(value = "03 保存巡检项项目列表", response = BPInspectItem.class)
    public ResultBean saveList(@RequestBody List<BPInspectItemBean> list) {
        inspectItemService.saveList(list);
        return ResultBean.defaultSuccessResult();
    }


    @GetMapping("/getById/{id}")
    @ApiOperation(value = "04 根据巡检项项目ID获取详情", response = BPInspectItem.class)
    @ApiImplicitParam(name = "id", value = "巡检项项目ID", paramType = "path", required = true)
    public ResultBean getById(@PathVariable Long id) {
        BPInspectItem inspectItem = inspectItemService.getById(id);
        return ResultBean.success(inspectItem);

    }

    @GetMapping("/delete/{id}")
    @RequiresPermissions("bp:inspect-item:delete")
    @ApiOperation(value = "05 根据巡检项项目ID删除")
    @ApiImplicitParam(name = "id", value = "巡检项项目ID", paramType = "path", required = true)
    public ResultBean delete(@PathVariable Long id) {
        inspectItemService.deleteById(id);
        return ResultBean.defaultSuccessResult();

    }

}
